import store from 'src/store'
import { validatenull } from 'src/util/validate'

export default ({ app, router, Vue }) => {
  router.beforeEach((to, from, next) => {
    // 缓冲设置
    if (to.meta.keepAlive === true && store.state.tags.tagList.some(ele => {
      return ele.value === to.fullPath
    })) {
      to.meta.$keepAlive = true
    } else {
      to.meta.$keepAlive = to.meta.keepAlive === true && validatenull(to.meta.$keepAlive)
    }
    if (to.path === '/404' || to.path === '/note') {
      return next()
    }

    return next()

  });

  router.beforeResolve((to, from, next) => {
    next();
  })

  router.afterEach((to, form) => {
    const title = store.getters.tag.label;
    router.$avueRouter.setTitle(title)
  });
}
